﻿using System;
using System.Collections.Generic;
using System.Web.SessionState;
using System.Web;
using System.Data;

namespace RDIFramework.WebApp.Modules.handler
{
    using RDIFramework.ServiceAdapter;
    using RDIFramework.Utilities;
    using RDIFramework.WebCommon;

    /// <summary>
    /// TableFieldAdminHandler 的摘要说明
    /// </summary>
    public class TableFieldAdminHandler : IHttpHandler, IRequiresSessionState
    {
        private string action
        {
            get
            {
                return RDIFramework.WebCommon.PublicMethod.GetString(getObj("action"));
            }
        }
        private object getObj(string key) { return RDIFramework.WebCommon.StringHelper.GetRequestObject(key); }


        public void ProcessRequest(HttpContext context)
        {
            switch (action)
            {
                case "GetTableNameAndCode":
                    GetTableNameAndCode(context);
                    break;
                case "GetDTByTable":
                    GetDTByTable(context);
                    break;
            }
        }

        private void GetTableNameAndCode(HttpContext ctx)
        {
            DataTable DTTableList = RDIFrameworkService.Instance.TableColumnsService.GetTableNameAndCode(Utils.UserInfo);
            ctx.Response.Write(RDIFramework.WebCommon.JSONhelper.ToJson(DTTableList));
        }

        private void GetDTByTable(HttpContext ctx)
        {
            string tableCode = RDIFramework.WebCommon.PublicMethod.GetString(getObj("tableCode"));
            DataTable DTTableColumns = RDIFrameworkService.Instance.TableColumnsService.GetDTByTable(Utils.UserInfo, tableCode);
            ctx.Response.Write(RDIFramework.WebCommon.JSONhelper.ToJson(DTTableColumns));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}